package com.qf.limit.controller;

import com.qf.limit.commons.base.BaseController;
import com.qf.limit.commons.r.R;
import com.qf.limit.entity.User;
import com.qf.limit.service.UserService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (User)表控制层
 *
 * @author makejava
 * @since 2024-09-10 09:36:48
 */
@RestController
@RequestMapping("user")
public class UserController extends BaseController<UserService> {

    @PostMapping
    public R register(@RequestBody @Validated User user) {
        System.out.println("用户注册-{}"+user);
        return R.succ(getBaseService().save(user));
    }

    //修改密码
    @PostMapping("/change-password")
    public R changePassword(@RequestBody @Validated ChangePasswordRequest request) {
        logger.info("用户密码修改请求 - {}", request);

        // Validate and change password
        boolean result = userService.changePassword(request.getUserId(), request.getOldPassword(), request.getNewPassword());

        if (result) {
            return R.succ("密码修改成功");
        } else {
            return R.fail("密码修改失败");
        }
    }
}

